﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.min.js"></script>
    <script src="/Scripts/SZHLCommon.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <title>提交申请</title>
    <script src="http://cdnjs.gtimg.com/cdnjs/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="../JS/Date/FT_Date.min.js"></script>
    <script>
        var jq = $.noConflict();
        jq(function () {
            var currYear = (new Date()).getFullYear();
            var opt = {
                date: { preset: 'date' },
                defaultopi: {
                    theme: 'android-ics light', //皮肤样式
                    display: 'modal', //显示方式
                    mode: 'scroller', //日期选择模式
                    lang: 'zh',
                    startYear: currYear - 5, //开始年份
                    endYear: currYear + 5, //结束年份
                    onSelect: function (valueText, inst) {
                        bxinfo.modelData.BXDate = valueText;
                    }
                }
            };
            jq("#appSDate").scroller(jq.extend(opt['date'], opt['defaultopi'])).scroller('setDate', new Date(), true);
            bxinfo.modelData.RBDate = jq("#BXDate").val();
        })
    </script>
    <script>
        var height = 0;
        var strId = ComFunJS.getQueryString("ids");

        var bxinfo = avalon.define({
            $id: "bxinfo",
            isforbid: "",
            modelData: { "BXZJE": 0, "BXContent": "", "ChaoSongRen": "", "Files": "", "ItemIds": strId, "BXDate": "" },
            mxData: {},
            delmx: function (el) {
                bxinfo.mxData.remove(el);
                bxinfo.modelData.BXZJE = bxinfo.modelData.BXZJE - el.BXJE;
            },
            savedata: function () {
                
                bxinfo.modelData.ItemIds = "";
                bxinfo.modelData.BXZJE = 0;
                for (var i = 0; i < bxinfo.mxData.length; i++) {
                    if (bxinfo.modelData.ItemIds == "") {
                        bxinfo.modelData.ItemIds = bxinfo.mxData[i].ID;
                    }
                    else {
                        bxinfo.modelData.ItemIds = bxinfo.modelData.ItemIds + "," + bxinfo.mxData[i].ID;
                    }


                    bxinfo.modelData.BXZJE = bxinfo.modelData.BXZJE + bxinfo.mxData[i].BXJE;
                }
                if (bxinfo.modelData.ItemIds == "") {
                    var el = $.tips({
                        content: "消费记录为空，请返回选择！",
                        stayTime: 2000,
                        type: "warn"
                    })
                }
                else {
                    var lg = $.loading({
                        content: '申请中...',
                    })
                    $.post("/API/WXAPI.ashx?Action=ADDJFBX&r=" + Math.random(), { "P1": JSON.stringify(bxinfo.modelData.$model) }, function (data) {
                        lg.hide();
                        var data = $.parseJSON(data);
                        if (data.ErrorMsg == "") {
                            $(".ui-footer").hide();
                            var el = $.tips({
                                content: "保存成功！",
                                stayTime: 2000,
                                type: "success"
                            })
                            el.on("tips:hide", function () {
                                window.location = "UI_JFBX_BXMX.html?r="+Math.random();
                            })
                        }
                        else {
                            $.tips({
                                content: "保存失败，原因：" + data.ErrorMsg,
                                stayTime: 2000,
                                type: "warn"
                            })
                        }

                    })
                }
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = document.documentElement.clientWidth - 5;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            }
        });

        function goback() {
            $("#content").show();
            $("#iframep").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                $("#kh_fzry").removeClass("ui-txt-muted");
                $("#kh_fzry").html(json.vuser);
                bxinfo.modelData.ChaoSongRen = json.vusername;
            }
            else {
                $("#kh_fzry").addClass("ui-txt-muted");
                $("#kh_fzry").html('请选择抄送人');
                bxinfo.modelData.ChaoSongRen = '';
            }

            $("#content").show();
            $("#iframep").hide();
        }

        avalon.ready(function () {
            height = document.documentElement.clientHeight - 11;
            if (strId != null) {
                var lg = $.loading({
                    content: '加载中...',
                })
                $.getJSON('/API/WXAPI.ashx?Action=GETJFBXITEMBYIDS&r=' + Math.random(), { p1: strId }, function (resultData) {
                    lg.hide();
                    if (resultData.ErrorMsg == "") {
                        bxinfo.mxData = resultData.Result;
                        bxinfo.modelData.BXZJE = resultData.Result1;
                    }
                })
            }
            $("#iframep").attr("src", "UI_PERSON.html?r=" + Math.random());
        })
    </script>
    <style>
        .ui-list > li {
            margin: 3px;
            padding-left: 15px;
        }
        .ui-form-item .wspan {
            width: 100%;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="bxinfo">
    <div id="content">
        <header class="ui-header ui-header-stable ui-border-b">
            <i class="ui-icon-return" onclick="history.back(-1)"></i><h1>申请报销</h1>
        </header>
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                提交申请
            </button>
            <button class="ui-btn-lg" onclick="history.back(-1)">
                取消
            </button>
        </div>

        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b">
                    <label>
                        报销时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="2015-07-10" id="appSDate" ms-duplex="modelData.BXDate" style="padding-left:0" />
                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        描述
                    </label>
                    <input type="text" placeholder="请输入描述" ms-duplex="modelData.BXContent" />
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        抄送人
                    </label>
                    <div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="kh_fzry" ms-click="selperson()">请选择抄送人</div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        总金额
                    </label>
                    <span class="wspan">{{modelData.BXZJE}}</span>
                </div>
                <div class="ui-form-item ui-border-b">
                    消费记录
                </div>
                <div class="ui-form ui-border-t">
                    <ul class="ui-list ui-list-pure">
                        <li class="ui-border ui-label-list" ms-repeat-el="mxData">
                            <p>
                                <span class="ui-txt-info">
                                    <label class="ui-label-s">
                                        {{el.LeiBie}}
                                    </label> {{el.BXJE}}元 {{el.BXDate|date("yyyy-MM-dd")}}
                                </span>
                                <span style="float:right"><button class="ui-btn ui-btn-danger" ms-click="delmx(el)" style="height:24px;line-height:24px">移除</button></span>
                            </p>
                            <p class="ui-txt-justify">事由：{{el.BXContent}}</p>
                        </li>
                    </ul>
                </div>

            </div>
        </section>
    </div>

    <iframe id="iframep" src="UI_PERSON.html" style="display:none"></iframe>
</body>
</html>
